package com.ruoyi.drawing.test;

import lombok.extern.slf4j.Slf4j;

/**
 * 是否回文
 *
 * @author ZhangYu
 * @date 2024/10/18 17:57
 */
@Slf4j
public class PlaLindRome {

    public static void main(String[] args) {
        log.info("--------------------------------------------------------------------------------------------{}", isPalindrome(-121));
    }

    public static boolean isPalindrome(int x) {
        int y = x;
        if (x < 0) {
            return false;
        }
        int xLength = 0;
        while (x != 0) {
            x /= 10;
            xLength++;
        }
        int[] xArray = new int[xLength];
        for (int i = xLength - 1; i >= 0; i--) {
            xArray[i] = y % 10;
            y = y / 10;
        }
        for (int i = 0; i < xLength; i++) {
            if (xArray[i] != xArray[xLength - i - 1]) {
                return false;
            }
        }
        return true;
    }

}
